﻿using System.Collections.ObjectModel;
using System.Globalization;
using UploadClient.Framework;
using UploadClient.Interfaces;
using UploadClient.Interfaces.Plugins;

namespace UploadClient.ViewModel
{
    public class FastConfigViewModel : ViewModelBase
    {
        public FastConfigViewModel(ICommunication communication)
        {
            PluginConfig = new ObservableCollection<IPluginConfig>();

            OpenConfig = new DelegateCommand(OpenConfig_Execute);

            Communication = communication;

            GetPluginConfig();
        }

        public string SelectedLanguage
        {
            get
            {
                return Communication.Options.SelectedLanguage;
            }
            set
            {
                LocalizationManager.UICulture = new CultureInfo(value);
                Communication.Options.SelectedLanguage = value;
                OnPropertyChanged("SelectedLanguage");
            }
        }

        public DelegateCommand OpenConfig { get; private set; }

        public ObservableCollection<IPluginConfig> PluginConfig { get; private set; }

        private void GetPluginConfig()
        {
            var pm = new PluginManager() { Option = Communication.Options };

            var items = pm.GetPlugins();

            foreach (var item in items)
            {
                foreach (var config in item.GetConfiguration())
                {
                    PluginConfig.Add(config);
                }
            }
        }

        private void OpenConfig_Execute(object param)
        {
            Communication.ShowWindow(new ConfigurationViewModel(){Communication = Communication});
        }
    }
}
